#include <iostream>
#include <signal.h>
#include<unistd.h>
void Print(sigset_t &pending)
{
    for (int sig = 31; sig > 0; sig--)
    {
        if (sigismember(&pending, sig))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}

void handler(int signum)
{
    std::cout << "get a signum: " << signum << std::endl;

    while (true)
    {
        sigset_t pending;
        sigpending(&pending); // 获取pending信号集

        Print(pending);
        sleep(3);
        break;
    }
    // exit(1);
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handler;

    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 3);
    act.sa_flags = 0;
    sigaction(2, &act, &oact); // 将老的方法保存一份

    while (true)
    {
        std::cout << "i'm a process, pid: " << getpid() << std::endl;
        sleep(1);
    }
    return 0;
}
